<template>
	<view>
		<uni-nav-bar :fixed="true" left-icon="back" title="实名认证" @clickLeft="leftBack" background-color="#318cff" color="#fff"></uni-nav-bar>
		<view class="dfj-bg-white dfj-pd-30 dfj-t-666">
			<view class="dfj-t-333 dfj-f-35">实名认证</view>
			<view class="dfj-t-999 dfj-mg-t-20">为保证用户账户安全，身份证信息我们会严格保密</view>
			<view class="dfj-t-333 dfj-f-30 dfj-mg-t-50 dfj-mg-b-20">身份证照片</view>
			<view class="dfj-flex dfj-flex-ai-c">
				<view class="dfj-flex-1 dfj-mg-r-30 dfj-t-c dfj-bd-e5e dfj-pd-tb-20" @click="frontUpload()">
					<block v-if="front">
						<image :src="front" style="width: 100%;height: 200rpx;"></image>
					</block>
					<block v-else>
						<view><image style="width: 50%;height: auto;" mode="widthFix" src="/static/img/my/front.png"></image></view>
						<view class="dfj-t-999">点击上传<text class="dfj-t-danger">人像面</text></view>
					</block>
				</view>
				<view class="dfj-flex-1 dfj-t-c dfj-bd-e5e dfj-pd-tb-20" @click="backUpload()">
					<block v-if="back">
						<image :src="back" style="width: 100%;height: 200rpx;"></image>
					</block>
					<block v-else>
						<view><image style="width: 50%;height: auto;" mode="widthFix" src="/static/img/my/back.png"></image></view>
						<view class="dfj-t-999">点击上传<text class="dfj-t-danger">国徽面</text></view>
					</block>
				</view>
			</view>
		</view>
		
		<!-- <view class="dfj-t-r dfj-pd-30 dfj-t-danger">
			信息有误手动编辑
		</view> -->
		
		<view class="dfj-bg-white dfj-t-666">
			<view class="dfj-flex dfj-flex-ai-c dfj-pd-lr-30 dfj-f-28">
				<view class="dfj-flex-1 dfj-pd-tb-20">真实姓名</view>
				<view class="dfj-flex-3">{{ info.name }}</view>
			</view>
			<view class="dfj-flex dfj-flex-ai-c dfj-pd-lr-30 dfj-f-28">
				<view class="dfj-flex-1 dfj-pd-tb-20">身份证号码</view>
				<view class="dfj-flex-3">{{ info.idNo }}</view>
			</view>
		</view>
		
		<view class="dfj-pd-50">
			<view class="dfj-t-c dfj-t-999 dfj-mg-b-20">
				<text class="dfj-t-danger">注：</text>根据有关规定，请上传真实信息
			</view>
			<view>
				<button type="primary" @click="btnCom">完成认证</button>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				front: '',
				back: '',
				token: '',
				info: {},
				loginInfo: ''
			}
		},
		onShow() {
			this.token = JSON.parse(localStorage.getItem('loginInfo')).token;
			this.loginInfo = JSON.parse(localStorage.getItem('loginInfo'));
		},
		methods: {
			leftBack() {
				uni.navigateBack();
			},
			frontUpload() {
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original'], //可以指定是原图还是压缩图，默认二者都有
				    success: (res)=> {
						this.front = res.tempFilePaths[0]
						//console.log(res.tempFiles[0])
						let tempFiles = res.tempFiles[0]
						uni.uploadFile({
							url: '/shopStreet/account/appDiscernIDCart',
							file: tempFiles,
							name: 'file',
							header: {
								'ssToken': this.token
							},
							formData: {
								cardSide: 'front'
							},
							success:(res2)=>{
								let data = JSON.parse(res2.data)
								console.log(res2)
								this.info = data.data
							},
							fail:(err)=>{
								console.log("失败")
								console.log(err)
							}
						})
				    }
				});
			},
			backUpload() {
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original'], //可以指定是原图还是压缩图，默认二者都有
				    success: (res)=> {
						this.back = res.tempFilePaths[0]
						//console.log(res.tempFiles[0])
						let tempFiles = res.tempFiles[0]
						uni.uploadFile({
							url: '/shopStreet/account/appDiscernIDCart',
							file: tempFiles,
							name: 'file',
							header: {
								'ssToken': this.token
							},
							formData: {
								cardSide: 'back'
							},
							success:(res2)=>{
								
							},
							fail:(err)=>{
								console.log("失败")
								console.log(err)
							}
						})
				    }
				});
			},
			btnCom() {
				this.$http({
					url: '/account/verifyIdcard',
					data: this.info,
					dataType: 'json'
				}).then(res=> {
					console.log(res)
					if(res.flag){
						uni.showToast({
							title: '提交成功'
						})
						this.loginInfo.userInfo.isAuthentication = 1
						localStorage.setItem('loginInfo', JSON.stringify(this.loginInfo))
						setTimeout(()=>{
							uni.hideToast();
							uni.navigateBack();
						},1500)
					}
				})
			}
		}
	}
</script>

<style>
</style>
